package logic

import (
	"context"
	"userrpc/userrpcclient"

	"userapi/internal/svc"
	"userapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AuthLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthLogic {
	return &AuthLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AuthLogic) Auth(req *types.AuthRequest) (resp *types.AuthResponse, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.UserRpc.Auth(context.Background(), &userrpcclient.AuthRequest{
		Username: req.Username,
		Name:     req.Name,
		IdCard:   req.IdCard,
	})
	if err != nil {
		return &types.AuthResponse{
			Code: int(res.Code),
			Msg:  res.Msg,
		}, nil
	}
	return &types.AuthResponse{
		Code: 200,
		Msg:  "实名成功",
	}, nil
}
